package org.linlinjava.litemall.db.domain;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;

@Data
@TableName("litemall_admin_order")
public class LitemallAdminOrder {
    public static final Boolean IS_DELETED = Deleted.IS_DELETED.value();

    public static final Boolean NOT_DELETED = Deleted.NOT_DELETED.value();

    @TableId
    private Integer id;

    private Integer adminId;

    private String username;

    private Integer shopId;

    private String shopName;

    private String orderRemark;

    private String erpOrderSn;

    private String orderSn;

    private Byte orderStatus;

    private String consignee;

    private String mobile;

    private String address;

    private BigDecimal freightPrice;

    private BigDecimal unitPrice;

    private BigDecimal orderPrice;

    private BigDecimal discount;

    private BigDecimal discountPrice;

    private BigDecimal discountLastPrice;

    private BigDecimal actualPrice;

    private Byte payStatus;

    private String handleRemark;

    private LocalDateTime payTime;

    private Byte shipStatus;

    private String shipSn;

    private String shipChannel;

    private LocalDateTime shipTime;

    private LocalDateTime confirmTime;

    private Short comments;

    private LocalDateTime endTime;

    private Byte serviceType;

    private LocalDateTime addTime;

    private LocalDateTime updateTime;

    private Boolean deleted;

    public enum Deleted {
        NOT_DELETED(new Boolean("0"), "未删除"),
        IS_DELETED(new Boolean("1"), "已删除");

        private final Boolean value;

        private final String name;

        Deleted(Boolean value, String name) {
            this.value = value;
            this.name = name;
        }

        public Boolean getValue() {
            return this.value;
        }

        public Boolean value() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        adminId("admin_id", "adminId", "INTEGER", false),
        username("userName", "username", "VARCHAR", false),
        shopId("shop_id", "shopId", "INTEGER", false),
        shopName("shop_name", "shopName", "VARCHAR", false),
        orderRemark("order_remark", "orderRemark", "VARCHAR", false),
        erpOrderSn("erp_order_sn", "erpOrderSn", "VARCHAR", false),
        orderSn("order_sn", "orderSn", "VARCHAR", false),
        orderStatus("order_status", "orderStatus", "TINYINT", false),
        consignee("consignee", "consignee", "VARCHAR", false),
        mobile("mobile", "mobile", "VARCHAR", false),
        address("address", "address", "VARCHAR", false),
        freightPrice("freight_price", "freightPrice", "DECIMAL", false),
        unitPrice("unit_price", "unitPrice", "DECIMAL", false),
        orderPrice("order_price", "orderPrice", "DECIMAL", false),
        discount("discount", "discount", "DECIMAL", false),
        discountPrice("discount_price", "discountPrice", "DECIMAL", false),
        discountLastPrice("discount_last_price", "discountLastPrice", "DECIMAL", false),
        actualPrice("actual_price", "actualPrice", "DECIMAL", false),
        payStatus("pay_status", "payStatus", "TINYINT", false),
        handleRemark("handle_remark", "handleRemark", "VARCHAR", false),
        payTime("pay_time", "payTime", "TIMESTAMP", false),
        shipStatus("ship_status", "shipStatus", "TINYINT", false),
        shipSn("ship_sn", "shipSn", "VARCHAR", false),
        shipChannel("ship_channel", "shipChannel", "VARCHAR", false),
        shipTime("ship_time", "shipTime", "TIMESTAMP", false),
        confirmTime("confirm_time", "confirmTime", "TIMESTAMP", false),
        comments("comments", "comments", "SMALLINT", false),
        endTime("end_time", "endTime", "TIMESTAMP", false),
        serviceType("service_type", "serviceType", "TINYINT", false),
        addTime("add_time", "addTime", "TIMESTAMP", false),
        updateTime("update_time", "updateTime", "TIMESTAMP", false),
        deleted("deleted", "deleted", "BIT", false);

        private static final String BEGINNING_DELIMITER = "`";

        private static final String ENDING_DELIMITER = "`";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}
